<template>
  <div class="project-audit-dialog">
    <el-dialog
      :title="title"
      :visible.sync="projectAuditShow"
      width="628px"
      :before-close="handleClose"
      :close-on-click-modal="false"
      custom-class="dialog-box"
    >
      <el-form
        :model="queryParams"
        :rules="rules"
        ref="queryParams"
        label-width="118px"
        class="demo-queryParams"
      >
        <el-form-item label="请选择">
          <el-select v-model="selectWay" placeholder="请选择" style="width:100%">
            <el-option
              v-for="dict in selectWayOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="审核结果" prop="approvalStatus" v-if="selectWay === 0">
          <el-radio-group v-model="queryParams.approvalStatus">
            <el-radio :label="2">通过</el-radio>
            <el-radio :label="3">退回修改</el-radio>
            <el-radio :label="4">驳回</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="审核意见" prop="approvalOpinion" v-if="selectWay === 0">
          <el-input
            type="textarea"
            v-model="queryParams.approvalOpinion"
            :rows="2"
            maxlength="200"
            show-word-limit
          ></el-input>
        </el-form-item>
        <div class="select-template" v-if="selectWay === 0">
          <el-dropdown trigger="click" @command="handleCommand" placement="top">
            <span class="el-dropdown-link">
              选择模版<i class="icon-arrow-down el-icon-folder-remove"></i>
            </span>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item
                icon="el-icon-circle-check"
                v-for="dict in selectDemoList"
                :key="dict.dictValue"
                :command="dict.dictValue"
                >{{ dict.dictLabel }}</el-dropdown-item
              >
            </el-dropdown-menu>
          </el-dropdown>
        </div>
        <el-form-item label="计划名称" prop="planId" v-if="selectWay === 1">
          <el-select v-model="queryParams.planId" placeholder="请选择" style="width:100%">
            <el-option
              v-for="dict in planNameOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            >
            </el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="handleClose">取 消</el-button>
        <el-button type="primary" @click="submitForm">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { getApprovalAdd } from "@/api/manage/manage";
import { getAnnualist, supplementToYear } from "@/api/manage/annualPlan";
export default {
  name: "declareDialog",
  props: {
    projectAuditShow: {
      type: Boolean,
      default: "",
    },
    type: {
      type: String,
      default: "",
    },
    proid: {
      type: String,
      default: "",
    },
  },
  inject: ["reload"],
  data() {
    return {
      title:'申报审核',
      rules: {
        approvalStatus: [
          { required: true, message: "请选择结果", trigger: "change" },
        ],
        // approvalOpinion: [
        //   {
        //     required: true,
        //     message: "请输入原因",
        //     trigger: ["blur", "change"],
        //   },
        // ],
         planId: [
          { required: true, message: "请选择项目", trigger: "change" },
        ],
      },
      queryParams: {
        approvalStatus: "",
        approvalOpinion: "",
        planId:undefined,
      },
      fileList: [],
      // 选择模板数据字典
      selectDemoList: [
        { dictValue: "方案描述不充分1", dictLabel: "方案描述不充分1" },
        { dictValue: "方案描述不充分2", dictLabel: "方案描述不充分2" },
        { dictValue: "方案描述不充分3", dictLabel: "方案描述不充分3" },
      ],
      selectWay:0,
      // 选择方式数据字典
      selectWayOptions: [
        { dictValue: 0, dictLabel: "审核" },
        { dictValue: 1, dictLabel: "转为年度项目" }
        ],
      // 计划名称字典查询
      planNameOptions: [{ dictValue: "", dictLabel: "" }],
    };
  },
  watch: {
    projectAuditShow(val) {
      if(val==true && this.proid){
          this.getAnnualOptions()
      }
    },
    selectWay(val){
      console.log(val);
      this.$refs.queryParams.resetFields();
      if(val&&val===1){
        this.title='年度计划'
      }else{
        this.title='申报审核'
      }
    }
  },
  methods: {
    /** 取消按钮 */
    handleClose() {
      this.selectWay=0;
      this.$refs.queryParams.resetFields();
      this.$emit("changeShowDialog", "false"); //调用父组件的自定义事件，并传值
    },
    /** 确定按钮 */
    submitForm() {
      this.queryParams.projectId = this.proid;
      this.queryParams.projectId = this.proid;
      this.$refs.queryParams.validate((valid) => {
        if (valid) {
          if(this.selectWay === 0){
              getApprovalAdd(this.queryParams).then((res) => {
              this.$message.success(res.msg)
              this.$refs.queryParams.resetFields();
              this.$emit("changeShowDialog", "false");
              this.reload();
            });
          }else{
            const planId = this.queryParams.planId
            supplementToYear(this.queryParams.planId,this.proid).then(res => {
              if (res.code === 200) {
                this.$message.success(res.msg)
                this.$refs.queryParams.resetFields();
                this.$emit("changeShowDialog", "false");
                this.$router.push('/business_manage/manage/annualplan/annualProjectPlan?id='+ planId + '&type=46')
              }
            })
          }
        }
      });
    },
    // 选择模板内容
    handleCommand(command) {
      // console.log(9999,command);
      this.queryParams.approvalOpinion = command;
    },
    // 获取年度计划
    getAnnualOptions() {
      getAnnualist({
        isState: 46,
        pageSize: 1000,
      }).then(res => {
        if (res.code === 200) {
          this.planNameOptions = res.rows.map(item => {
            return {
              dictValue: item.planId,
              dictLabel: item.name,
            }
          })
        }
      })
    }
  },
};
</script>

<style lang="scss">
.project-audit-dialog .dialog-box .el-form-item .el-input__inner {
  width: 100%;
}
.project-audit-dialog .dialog-box .el-form-item .el-textarea__inner {
  width: 100%;
}
.project-audit-dialog {
  // 下载模板样式修改
  .select-template {
    .el-dropdown-link {
      color: #3171ee;
    }
    .icon-arrow-down {
      margin-left: 10px;
      color: #3171ee;
    }
    // width: 100%;
    display: flex;
    align-items: center;
    justify-content: right;
    font-size: 14px;
    font-family: PingFang SC, PingFang SC-Regular;
    font-weight: 400;
    text-align: LEFT;
    color: #3171ee;
    margin-left: 30%;
    margin-bottom: 20px;
    cursor: pointer;
    img {
      margin-left: 10px;
    }
  }
}
</style>
